import { Component, OnInit } from '@angular/core';
import { ActivatedRoute, NavigationEnd, Router } from '@angular/router';
import {map, filter} from "rxjs/operators";

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.scss']
})
export class AppComponent implements OnInit {
  isCollapsed = false;
  title: any;
  constructor(private router: Router, private activatedRoute: ActivatedRoute) {
   
  }

  ngOnInit() {
    this.router.events.pipe(filter(e => e instanceof NavigationEnd),map(() => {
      let child = this.activatedRoute.firstChild;
      while (child.firstChild) {
        child = child.firstChild;
      }
      if (child.snapshot.data['title']) {
        return child.snapshot.data['title'];
      }
      return '';
    })).subscribe(title => {
      this.title = title;
    });
  }
  
}
